package com.forenow.demo.IOtest;

import java.io.*;
import java.util.Iterator;
import java.util.List;

public class Operator {
    public boolean write(List<Student> list,String fileName){
        FileWriter fw = null;
        BufferedWriter bw = null;
        try {
            fw = new FileWriter(fileName);
            bw = new BufferedWriter(fw);
            //对list集合遍历
            Iterator<Student> it = list.iterator();
            while(it.hasNext()){
                Student stu = it.next();
                String str = stu.getSid()+" "+stu.getName()+" "+stu.getAge()+" "+ stu.getSchool();
                //将文件写到Student.txt文件中
                bw.write(str);
                bw.newLine();//换行
            }
            //关闭资源
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }
    public  List<Student[]> read(String filename) {
       FileReader fr=null;
       BufferedReader br = null;
        List<Student> list=null;
        Student student=new Student();
        String[] s = new String[0];
        try {
            fr=new FileReader(filename);
            br=new BufferedReader(fr);
            br.read();
            String line = br.readLine();
            for (int i = 0; i <list.size() ; i++) {
                s = line.split(" ");
            }
            for (int i = 0; i < s.length; i++) {
                System.out.println(s[i]);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                br.close();
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return null;
    }
}
